using System;
using System.Web.UI;

namespace Altairis.FluffyCloud.WebCore.DynamicData.FieldTemplates {

    public partial class UrlField : System.Web.DynamicData.FieldTemplateUserControl {

        public override Control DataControl {
            get {
                return HyperLinkUrl;
            }
        }

        protected override void OnDataBinding(EventArgs e) {
            HyperLinkUrl.NavigateUrl = ProcessUrl(FieldValueString);
        }

        private string ProcessUrl(string url) {
            if (url.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase) || url.StartsWith("https://", StringComparison.CurrentCultureIgnoreCase)) {
                return url;
            }

            return "http://" + url;
        }
    }
}